package com.gpframework.module.controller.module;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gpframework.common.annotation.Log;
import com.gpframework.common.core.controller.BaseController;
import com.gpframework.common.core.domain.AjaxResult;
import com.gpframework.common.core.page.TableDataInfo;
import com.gpframework.common.enums.BusinessType;
import com.gpframework.common.utils.poi.ExcelUtil;
import com.gpframework.module.module.domain.BrandStoreLog;
import com.gpframework.module.module.domain.req.BrandStoreLogAdd;
import com.gpframework.module.module.domain.req.BrandStoreLogReq;
import com.gpframework.module.module.domain.req.BrandStoreLogUpdate;
import com.gpframework.module.module.domain.vo.BrandStoreLogVo;
import com.gpframework.module.module.service.IBrandStoreLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;

/**
 * @ClassName BrandStoreLogController
 * @Author gpframework
 * @Date 2022-03-25
 * @Version 1.0.0
 * @Description 门店日志Controller
 */
@Validated
@Api(tags = "门店日志")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@SuppressWarnings({"rawtypes", "unchecked"})
@RequestMapping("/module/brandStoreLog")
public class BrandStoreLogController extends BaseController {

    private final IBrandStoreLogService iBrandStoreLogService;

    /**
     * @Description 分页
     * @Author gpframework
     * @Date 2022-03-25
     * @Param brandStoreLog
     * @Return TableDataInfo
     */
    @ApiOperation("列表")
    @PreAuthorize("@ss.hasPermi('module:brandStoreLog:list')")
    @GetMapping("/list")
    public TableDataInfo<BrandStoreLogVo> list(BrandStoreLogReq brandStoreLogReq) {
        startPage();
        QueryWrapper<BrandStoreLog> lqw = new QueryWrapper<BrandStoreLog>();
        brandStoreLogReq.generatorQuery(lqw, true);
        List<BrandStoreLogVo> list = iBrandStoreLogService.listVo(lqw);
        return getDataTable(list);
    }

    /**
     * @Description 新增
     * @Author gpframework
     * @Date 2022-03-25
     * @Param brandStoreLog
     * @Return TableDataInfo
     */
    @ApiOperation("新增")
    @PreAuthorize("@ss.hasPermi('module:brandStoreLog:add')")
    @Log(title = "添加门店日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody BrandStoreLogAdd brandStoreLogAdd) {
        BrandStoreLog brandStoreLog = Convert.convert(new TypeReference<BrandStoreLog>() {
        }, brandStoreLogAdd);
        return toAjax(iBrandStoreLogService.save(brandStoreLog) ? 1 : 0);
    }

    /**
     * @Description 修改
     * @Author gpframework
     * @Date 2022-03-25
     * @Param brandStoreLog
     * @Return TableDataInfo
     */
    @ApiOperation("修改")
    @PreAuthorize("@ss.hasPermi('module:brandStoreLog:edit')")
    @Log(title = "修改门店日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody BrandStoreLogUpdate brandStoreLogUpdate) {
        BrandStoreLog brandStoreLog = Convert.convert(new TypeReference<BrandStoreLog>() {
        }, brandStoreLogUpdate);
        return toAjax(iBrandStoreLogService.updateById(brandStoreLog) ? 1 : 0);
    }


    /**
     * @Description 导出
     * @Author gpframework
     * @Date 2022-03-25
     * @Param brandStoreLog
     * @Return TableDataInfo
     */

    @PreAuthorize("@ss.hasPermi('module:brandStoreLog:export')")
    @Log(title = "导出门店日志", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BrandStoreLogReq brandStoreLogReq) {
        QueryWrapper<BrandStoreLog> lqw = new QueryWrapper<BrandStoreLog>();
        brandStoreLogReq.generatorQuery(lqw, true);
        List<BrandStoreLogVo> list = iBrandStoreLogService.listVo(lqw);
        ExcelUtil<BrandStoreLogVo> util = new ExcelUtil<BrandStoreLogVo>(BrandStoreLogVo.class);
        return util.exportExcel(list, "brandStoreLog");
    }

    /**
     * @Description 详情
     * @Author gpframework
     * @Date 2022-03-25
     * @Param brandStoreLog
     * @Return TableDataInfo
     */
    @ApiOperation("详情")
    @PreAuthorize("@ss.hasPermi('module:brandStoreLog:query')")
    @GetMapping(value = "/{storeAuditRecordId}")
    public AjaxResult<BrandStoreLogVo> getInfo(@PathVariable("storeAuditRecordId") Long storeAuditRecordId) {
        return AjaxResult.success(iBrandStoreLogService.getVoById(storeAuditRecordId));
    }


    /**
     * @Description 删除
     * @Author gpframework
     * @Date 2022-03-25
     * @Param brandStoreLog
     * @Return TableDataInfo
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('module:brandStoreLog:remove')")
    @Log(title = "删除门店日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{storeAuditRecordIds}")
    public AjaxResult remove(@PathVariable Long[] storeAuditRecordIds) {
        return toAjax(iBrandStoreLogService.removeByIds(Arrays.asList(storeAuditRecordIds)) ? 1 : 0);
    }
}
